#include <stdint.h>

#include "vicl.h"

// this establishes connectivity with the vmware server.  Return: 0 for success, -1 for failure
int setup_vmware_connection(const char* hostname, const char* username, const char* password)
{
    jobHandle = VIX_INVALID_HANDLE;
    hostHandle = VIX_INVALID_HANDLE;

    // send the connect request
    jobHandle = VixHost_Connect(VIX_API_VERSION,
                    VIX_SERVICEPROVIDER_VMWARE_VI_SERVER,
                    hostname,
                    0,
                    username,
                    password,
                    0,
                    VIX_INVALID_HANDLE,
                    NULL,
                    NULL);
         
    // wait for the job to complete           
    err = VixJob_Wait(jobHandle, 
                      VIX_PROPERTY_JOB_RESULT_HANDLE, 
                      &hostHandle,
                      VIX_PROPERTY_NONE);
                      
    if(VIX_FAILED(err))
    {
        VICL_ERROR("VixHost_Connect failed\n");
        return -1;
    }
    
    // release the active job handle
    Vix_ReleaseHandle(jobHandle);
    
    return 0;
}
